// vuex.d.ts
import { ComponentCustomProperties } from 'vue'
import { Store, createStore } from 'vuex'

declare module '@vue/runtime-core' {
  // 声明自己的 store state
  interface State {
    count: number
  }

  // 为 `this.$store` 提供类型声明
  interface ComponentCustomProperties {
    $store: Store<State>
  }
}


const store = createStore({
  state: {
    count: 0
  },
  getters: {
    incTen(state) {
      return state.count += 10
    }
  },
  mutations: {
    incCount(state:any):void {
      state.count++
    },
    decCount(state:any):void {
      state.count--
    },
    setCount(state:any, payload:number):void {
      state.count = payload
    }
  },
  actions: {
    DoincCount(context , products) {
      context.commit("incCount")
    },
    DodecCount({ commit, state }, products) {
      commit("decCount")
    },
    DosetCount({ commit, state }, products) {
      commit("setCount", products)
    },
  },
  modules: {

  }
})

export default store